package com.qf.ebook.controller;

import com.qf.ebook.util.R;
import com.qf.ebook.vo.ResultVO;
import org.quartz.JobKey;
import org.quartz.SchedulerException;
import org.quartz.impl.StdScheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 控制定时任务
 */
@RestController
@RequestMapping("/task")
public class TaskController {
    @Autowired
    private StdScheduler stdScheduler;

    @GetMapping("/suspend")
    public ResultVO suspend(String jobName, String groupName) throws SchedulerException {
        // 暂停某个任务
        stdScheduler.pauseJob(JobKey.jobKey(jobName,groupName));
        // 返回成功
        return R.ok();
    }

    @GetMapping("/recovery")
    public ResultVO recovery(String jobName, String groupName) throws SchedulerException {
        // 恢复某个任务
        stdScheduler.resumeJob(JobKey.jobKey(jobName, groupName));
        // 返回成功
        return R.ok();
    }
}
